home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / manageme / tcpdump-.001 / tcpdump-~ / tcpdump-3.0.2-linux / tcpdump-3.0.2 / print-llc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-15  |  5.1 KB  |  197 lines

  1. /*
  2.  * Copyright (c) 1992, 1993, 1994
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that: (1) source code distributions
  7.  * retain the above copyright notice and this paragraph in its entirety, (2)
  8.  * distributions including binary code include the above copyright notice and
  9.  * this paragraph in its entirety in the documentation or other materials
  10.  * provided with the distribution, and (3) all advertising materials mentioning
  11.  * features or use of this software display the following acknowledgement:
  12.  * ``This product includes software developed by the University of California,
  13.  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  14.  * the University nor the names of its contributors may be used to endorse
  15.  * or promote products derived from this software without specific prior
  16.  * written permission.
  17.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  18.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  19.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20.  */
  21.  
  22. /*
  23.  * Code by Matt Thomas, Digital Equipment Corporation
  24.  *    with an awful lot of hacking by Jeffrey Mogul, DECWRL
  25.  */
  26.  
  27. #ifndef lint
  28. static  char rcsid[] =
  29.     "@(#)$Header: print-llc.c,v 1.13 94/06/14 20:18:45 leres Exp $";
  30. #endif
  31.  
  32. #include <sys/param.h>
  33. #include <sys/time.h>
  34. #include <sys/types.h>
  35.  
  36. #include <netinet/in.h>
  37.  
  38. #include <ctype.h>
  39. #include <errno.h>
  40. #include <netdb.h>
  41. #include <signal.h>
  42. #include <stdio.h>
  43.  
  44. #include "interface.h"
  45. #include "addrtoname.h"
  46. #include "extract.h"            /* must come after interface.h */
  47.  
  48. #include "llc.h"
  49.  
  50. static struct token cmd2str[] = {
  51.     { LLC_UI,    "ui" },
  52.     { LLC_TEST,    "test" },
  53.     { LLC_XID,    "xid" },
  54.     { LLC_UA,    "ua" },
  55.     { LLC_DISC,    "disc" },
  56.     { LLC_DM,    "dm" },
  57.     { LLC_SABME,    "sabme" },
  58.     { LLC_FRMR,    "frmr" },
  59.     { 0,        NULL }
  60. };
  61.  
  62. /*
  63.  * Returns non-zero IFF it succeeds in printing the header
  64.  */
  65. int
  66. llc_print(const u_char *p, int length, int caplen,
  67.       const u_char *esrc, const u_char *edst)
  68. {
  69.     struct llc llc;
  70.     register u_short et;
  71.     register int ret;
  72.  
  73.     if (caplen < 3) {
  74.         (void)printf("[|llc]");
  75.         default_print((u_char *)p, caplen);
  76.         return(0);
  77.     }
  78.  
  79.     /* Watch out for possible alignment problems */
  80.     bcopy((char *)p, (char *)&llc, min(caplen, sizeof(llc)));
  81.  
  82.     if (llc.ssap == LLCSAP_GLOBAL && llc.dsap == LLCSAP_GLOBAL) {
  83.         ipx_print(p, length);
  84.         return (1);
  85.     }
  86. #ifdef notyet
  87.     else if (p[0] == 0xf0 && p[1] == 0xf0)
  88.         netbios_print(p, length);
  89. #endif
  90.     if (llc.ssap == LLCSAP_ISONS && llc.dsap == LLCSAP_ISONS
  91.         && llc.llcui == LLC_UI) {
  92.         isoclns_print(p + 3, length - 3, caplen - 3, esrc, edst);
  93.         return (1);
  94.     }
  95.  
  96.     if (llc.ssap == LLCSAP_SNAP && llc.dsap == LLCSAP_SNAP
  97.         && llc.llcui == LLC_UI) {
  98.         if (caplen < sizeof(llc)) {
  99.             (void)printf("[|llc-snap]");
  100.             default_print((u_char *)p, caplen);
  101.             return (0);
  102.         }
  103.         if (vflag)
  104.             (void)printf("snap %s ", protoid_string(llc.llcpi));
  105.  
  106.         caplen -= sizeof(llc);
  107.         length -= sizeof(llc);
  108.         p += sizeof(llc);
  109.  
  110.         /* This is an encapsulated Ethernet packet */
  111.         et = EXTRACT_SHORT(&llc.ethertype[0]);
  112.         ret = ether_encap_print(et, p, length, caplen);
  113.         if (ret)
  114.             return (ret);
  115.     }
  116.  
  117.     if ((llc.ssap & ~LLC_GSAP) == llc.dsap) {
  118.         if (eflag)
  119.             (void)printf("%s ", llcsap_string(llc.dsap));
  120.         else
  121.             (void)printf("%s > %s %s ",
  122.                     etheraddr_string(esrc),
  123.                     etheraddr_string(edst),
  124.                     llcsap_string(llc.dsap));
  125.     } else {
  126.         if (eflag)
  127.             (void)printf("%s > %s ",
  128.                 llcsap_string(llc.ssap & ~LLC_GSAP),
  129.                 llcsap_string(llc.dsap));
  130.         else
  131.             (void)printf("%s %s > %s %s ",
  132.                 etheraddr_string(esrc),
  133.                 llcsap_string(llc.ssap & ~LLC_GSAP),
  134.                 etheraddr_string(edst),
  135.                 llcsap_string(llc.dsap));
  136.     }
  137.  
  138.     if ((llc.llcu & LLC_U_FMT) == LLC_U_FMT) {
  139.         const char *m;
  140.         char f;
  141.         m = tok2str(cmd2str, "%02x", LLC_U_CMD(llc.llcu));
  142.         switch ((llc.ssap & LLC_GSAP) | (llc.llcu & LLC_U_POLL)) {
  143.             case 0:            f = 'C'; break;
  144.             case LLC_GSAP:        f = 'R'; break;
  145.             case LLC_U_POLL:        f = 'P'; break;
  146.             case LLC_GSAP|LLC_U_POLL:    f = 'F'; break;
  147.             default:            f = '?'; break;
  148.         }
  149.  
  150.         printf("%s/%c", m, f);
  151.  
  152.         p += 3;
  153.         length -= 3;
  154.         caplen -= 3;
  155.  
  156.         if ((llc.llcu & ~LLC_U_POLL) == LLC_XID) {
  157.             if (*p == LLC_XID_FI) {
  158.             printf(": %02x %02x", p[1], p[2]);
  159.             p += 3;
  160.             length -= 3;
  161.             caplen -= 3;
  162.             }
  163.         }
  164.     } else {
  165.         char f;
  166.         llc.llcis = ntohs(llc.llcis);
  167.         switch ((llc.ssap & LLC_GSAP) | (llc.llcu & LLC_U_POLL)) {
  168.             case 0:            f = 'C'; break;
  169.             case LLC_GSAP:        f = 'R'; break;
  170.             case LLC_U_POLL:        f = 'P'; break;
  171.             case LLC_GSAP|LLC_U_POLL:    f = 'F'; break;
  172.             default:            f = '?'; break;
  173.         }
  174.  
  175.         if ((llc.llcu & LLC_S_FMT) == LLC_S_FMT) {
  176.             static char *llc_s[] = { "rr", "rej", "rnr", "03" };
  177.             (void)printf("%s (r=%d,%c)",
  178.                 llc_s[LLC_S_CMD(llc.llcis)],
  179.                 LLC_IS_NR(llc.llcis),
  180.                 f);
  181.         } else {
  182.             (void)printf("I (s=%d,r=%d,%c)",
  183.                 LLC_I_NS(llc.llcis),
  184.                 LLC_IS_NR(llc.llcis),
  185.                 f);
  186.         }
  187.         p += 4;
  188.         length -= 4;
  189.         caplen -= 4;
  190.     }
  191.     (void)printf(" len=%d", length);
  192.     if (caplen > 0) {
  193.         default_print_unaligned(p, caplen);
  194.     }
  195.     return(1);
  196. }
  197.